import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import Legacy from '@vitejs/plugin-legacy'
import Layouts from 'vite-plugin-vue-layouts'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  server: {
    port: 9090
  },
  build: {
    target: 'es2015'
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [
    vue({
      include: [/\.vue$/],
      reactivityTransform: true
    }),
    Legacy({
      targets: ['defaults', 'not IE 11'],
      modernPolyfills: true
    }),
    Pages({
      dirs: [{ dir: 'src/pages', baseRoute: '/' }],
      extensions: ['vue'],
      exclude: ['**/components/*.*']
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    Layouts({ defaultLayout: 'default' })
  ],
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve('src/assets/style/variables.less')}";`
        },
        javascriptEnabled: true
      }
    }
  }
})
